package databaseTransaction;

import java.util.ArrayList;
import java.util.List;

import util.Relationship;

import lexer.TokenConstant;

public class TableField {
	private String name;
	private int type;
	private int length;
	private List<Object> extra;
	private Relationship relationship;

	public TableField() {
		extra = new ArrayList<Object>();
		this.name = "";
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getType() {
		return this.type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getLength() {
		return this.length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public List<Object> getExtra() {
		return this.extra;
	}

	public void setExtra(List<Object> extra) {
		this.extra = extra;
	}

	public void addExtraValue(Object value) {
		this.extra.add(value);
	}

	public String parseType() {
		String fieldType = "";
		switch (type) {
		case TokenConstant.INT:
			fieldType = "int";
			break;
		case TokenConstant.VARCHAR:
			fieldType = "String";
			break;
		case TokenConstant.DATE:
			fieldType = "java.sql.Date";
			break;
		case TokenConstant.BOOLEAN:
			fieldType = "boolean";
			break;
		}
		return fieldType;
	}

	public String parseDBType() {
		String fieldType = "";
		switch (type) {
		case TokenConstant.INT:
			fieldType = "INT";
			break;
		case TokenConstant.VARCHAR:
			fieldType = "VARCHAR";
			break;
		case TokenConstant.DATE:
			fieldType = "DATE";
			break;
		case TokenConstant.BOOLEAN:
			fieldType = "BOOLEAN";
			break;
		}

		return fieldType;
	}

	public Relationship getRelationship() {
		return relationship;
	}

	public void setRelationship(Relationship relationship) {
		this.relationship = relationship;
	}
}